package handling.login.handler;

import client.MapleCharacter;
import client.MapleClient;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.mina.core.session.IoSession;
import tools.data.LittleEndianAccessor;
import tools.packet.LoginPacket;

public class ViewCharHandler {

    public static void handlePacket(LittleEndianAccessor slea, MapleClient c) {
        Map<Byte, List> worlds = new HashMap<>();
        List<MapleCharacter> chars = c.loadCharacters(0);
        c.getSession().write(LoginPacket.showAllCharacter(chars.size()));
        for (MapleCharacter chr : chars) {
            if (chr != null) {
                ArrayList chrr;
                if (!worlds.containsKey(Byte.valueOf(chr.getWorld()))) {
                    chrr = new ArrayList();
                    worlds.put(Byte.valueOf(chr.getWorld()), chrr);
                } else {
                    chrr = (ArrayList) worlds.get(Byte.valueOf(chr.getWorld()));
                }
                chrr.add(chr);
            }
        }
        for (Map.Entry w : worlds.entrySet()) {
            c.getSession().write(LoginPacket.showAllCharacterInfo(((Byte) w.getKey()).byteValue(), (List) w.getValue(), c.getSecondPassword()));
        }
    }
}

/* Location:           C:\Users\文炳\Desktop\CXFBY\114Maplewing.jar
 * Qualified Name:     handling.login.handler.ViewCharHandler
 * JD-Core Version:    0.6.2
 */